"""Routes configuration

The more specific and detailed routes should be defined first so they
may take precedent over the more generic routes. For more information
refer to the routes manual at http://routes.groovie.org/docs/
"""
from pylons import config
from routes import Mapper

def make_map():
    """Create, configure and return the routes Mapper"""
    map = Mapper(directory=config['pylons.paths']['controllers'],
                 always_scan=config['debug'])

    # The ErrorController route (handles 404/500 error pages); it should
    # likely stay at the top, ensuring it can always be resolved
    map.connect('error/:action/:id', controller='error')

    # CUSTOM ROUTES HERE
    map.resource('project', 'projects')
    map.resource('clientrequirement', 'clientrequirements')
    map.resource('acceptancetest', 'acceptancetests')
    map.resource('productrequirement', 'productrequirements')
    map.resource('testcase', 'testcases')
    map.resource('product', 'products')
    map.resource('priority', 'priorities')
    map.resource('status', 'statuses')
    map.resource('crtype', 'crtypes')
    map.resource('impact', 'impacts')
    map.resource('xuser', 'xusers')
    map.resource('risk', 'risks')
    #------------ LOGIN ----------------
    map.connect( '/login',
                controller='login',
                action='index',
                conditions=dict(method=['POST']))
    #------------CLIENT REQUIREMENTS----------------
    map.connect('clientrequirements_by_project', ':project/clientrequirements',
                controller='clientrequirements',
                action='listByProject',
                requirements=dict(project='\d+'),
                conditions=dict(method=['GET']))

    map.connect('new_clientrequirement_by_project', ':project/clientrequirements/new',
                controller='clientrequirements',
                action='newByProject',
                conditions=dict(method=['GET']))

    map.connect('create_clientrequirements_by_project', ':project/clientrequirements',
                controller='clientrequirements',
                action='createByProject',
                requirements=dict(project='\d+'),
                conditions=dict(method=['POST']))
    #-----------ACEPTANCE TESTS -------------------
    map.connect('acceptancetests_by_project', ':project/acceptancetests',
                controller='acceptancetests',
                action='listByProject',
                requirements=dict(project='\d+'),
                conditions=dict(method=['GET']))

    map.connect('acceptancetests_by_requirement', ':project/:requirement/acceptancetests',
                controller='acceptancetests',
                action='listByRequirement',
                requirements=dict(project='\d+', requirement='\d+'),
                conditions=dict(method=['GET']))

    map.connect('new_acceptancetest_by_project', ':project/acceptancetests/new',
                controller='acceptancetests',
                action='newByProject',
                requirements=dict(project='\d+'),
                conditions=dict(method=['GET']))

    map.connect('new_acceptancetest_by_requirement', ':project/:requirement/acceptancetests/new',
                controller='acceptancetests',
                action='newByRequirement',
                requirements=dict(project='\d+', requirement='\d+'),
                conditions=dict(method=['GET']))

    map.connect('create_acceptancetest_by_project', ':project/acceptancetests',
                controller='acceptancetests',
                action='createByProject',
                requirements=dict(project='\d+'),
                conditions=dict(method=['POST']))

    map.connect('create_acceptancetest_by_requirement', ':project/:requirement/acceptancetests',
                controller='acceptancetests',
                action='createByRequirement',
                requirements=dict(project='\d+', requirement='\d+'),
                conditions=dict(method=['POST']))
    #---------PRODUCT REQUIREMENTS------------------
    map.connect('productrequirements_by_project', ':project/productrequirements',
                controller='productrequirements',
                action='listByProject',
                requirements=dict(project='\d+'),
                conditions=dict(method=['GET']))

    map.connect('new_productrequirement_by_project', ':project/productrequirements/new',
                controller='productrequirements',
                action='newByProject',
                requirements=dict(project='\d+'),
                conditions=dict(method=['GET']))

    map.connect('create_productrequirements_by_project', ':project/productrequirements',
                controller='productrequirements',
                action='createByProject',
                requirements=dict(project='\d+'),
                conditions=dict(method=['POST']))
    # ------- TEST CASES --------------
    map.connect('testcases_by_project', ':project/testcases',
                controller='testcases',
                action='listByProject',
                requirements=dict(project='\d+'),
                conditions=dict(method=['GET']))

    map.connect('testcases_by_requirement', ':project/:requirement/testcases',
                controller='testcases',
                action='listByRequirement',
                requirements=dict(project='\d+', requirement='\d+'),
                conditions=dict(method=['GET']))

    map.connect('new_testcase_by_project', ':project/testcases/new',
                controller='testcases',
                action='newByProject',
                requirements=dict(project='\d+'),
                conditions=dict(method=['GET']))

    map.connect('new_testcase_by_requirement', ':project/:requirement/testcases/new',
                controller='testcases',
                action='newByRequirement',
                requirements=dict(project='\d+', requirement='\d+'),
                conditions=dict(method=['GET']))

    map.connect('create_testcases_by_project', ':project/testcases',
                controller='testcases',
                action='createByProject',
                requirements=dict(project='\d+'),
                conditions=dict(method=['POST']))

    map.connect('create_testcase_by_requirement', ':project/:requirement/testcases',
                controller='testcases',
                action='createByRequirement',
                requirements=dict(project='\d+', requirement='\d+'),
                conditions=dict(method=['POST']))
    #------------- PRODUCTS -----------------
    map.connect('products_by_project', ':project/products',
                controller='products',
                action='listByProject',
                requirements=dict(project='\d+'),
                conditions=dict(method=['GET']))

    map.connect('new_product_by_project', ':project/products/new',
                controller='products',
                action='newByProject',
                requirements=dict(project='\d+'),
                conditions=dict(method=['GET']))

    map.connect('create_products_by_project', ':project/products',
                controller='products',
                action='createByProject',
                requirements=dict(project='\d+'),
                conditions=dict(method=['POST']))
    #-----------ASSOCIATIONS----------------
    map.connect('associationtype', ':project/associations/:type',
                controller='associations',
                action='listByType',
                requirements=dict(type='\w+', project='\d+'),
                conditions=dict(method=['GET']))

    map.connect('createassociation', ':project/associations/:type',
                controller='associations',
                action='createByType',
                requirements=dict(type='\w+', project='\d+'),
                conditions=dict(method=['POST']))
    #---------TRAZABILITY------------------
    map.connect(':project/trazability/:type',
                controller='trazability',
                action='listByProjectType',
                requirements=dict(type='\w+', project='\d+'),
                conditions=dict(method=['GET']))

    #---------RESUMEN/INDICADORES------------------
    map.connect(':project/resumen/indicators',
                controller='indicators',
                action='listByProject',
                requirements=dict(project='\d+'),
                conditions=dict(method=['GET']))

    map.resource('association', 'associations')
    '''
    map.connect('projects',
                controller='projects',
                action='list',
                conditions=dict(method=['GET']))

    map.connect('projects/:id',
                controller='projects',
                action='view',
                conditions=dict(method=['GET']))

    map.connect('projects',
                controller='projects',
                action='add',
                conditions=dict(method=['POST']))

    map.connect('projects/:id',
                controller='projects',
                action='edit',
                conditions=dict(method=['PUT']))

    map.connect('projects/:id',
                controller='projects',
                action='delete',
                conditions=dict(method=['DELETE']))
    '''

    #map.connect(':controller/:action/:id')
    map.connect('*url', controller='template', action='view')

    return map
